# -*- coding: utf-8 -*-

from openerp.addons.web import http
from openerp.addons.web.http import request
from openerp import SUPERUSER_ID
import simplejson
import random
import time
import datetime
import os
import sys

class PPTControllers(http.Controller):
    '''
        下载指定的ppt文件
    '''
    @http.route('/PPT/get_ppt/<ppt_id>', type='http', auth="user", methods=['GET'], website=True)
    def get_ppt(self, ppt_id, **kw):
        # 找到需要下载的文件所在的服务器路径
        output_file_path = os.path.join(os.getcwd(),'attachments/ppts/',ppt_id+'.pptx')
        file = open(output_file_path, 'r')
        filesize = os.path.getsize(output_file_path)

        # 设置response的HTTP header的内容类型为pptx
        return request.make_response(file,
                                     headers=[
                                         ('Content-Type', 'application/vnd.openxmlformats-officedocument.presentationml.presentation'),
                                         ('Content-Length', str(filesize))
                                              ]
                                     )
